package com.itheima.homework;

import java.util.*;

public class Test1 {
    /**
     * 4 题目
     * 	统计字符串中每一个字符的出现个数
     * 	例如:字符串”aabbccdd”
     * 输出结果为:a(2)b(2)c(2)d(2)
     */
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入字符串");
        String s = sc.nextLine();
        String[] str = s.split("");
        TreeMap<String, Integer> map = new TreeMap<>();
        int count = 0;



            for (int i = 0; i < str.length; i++) {

                if (map.containsKey(str[i])){
                    count++;
                    map.put(str[i],count);
                }else{
                    count = 1;
                    map.put(str[i],count);
                }
            }

        map.forEach(
                    (key,value) ->{
                        System.out.print(key + "(" + value + ")");
                    }
            );
        }






        

}
